var viewStatus = function () {
    this.statusKeyArray = [];
    this.status = {};
    this.VIEW = {};
    this.BoardView = {};
    this.OptionsView = {};
    this.SelectObject = null;
};

viewStatus.prototype.startMouseListener = function (obj) {
    this.VIEW.showInnerMark();
    var event = (e) => {
        $(document).off('mouseup', event);
        this.VIEW.hideInnerMark();
        if (e.target.id == 'innerMark') {
            var viewObj = new obj({}, this.VIEW, this);
            this.addObject(viewObj, false, e);
        }
    };
    $(document).on('mouseup', event);
};

viewStatus.prototype.setView = function (view) {
    this.VIEW = view;
    this.BoardView = view.viewerBoard;
};

viewStatus.prototype.setOptionsView = function (view) {
    this.OptionsView = view;
    this.VIEW.onCancel(this.cancelSelectObject);
};
viewStatus.prototype.cancelSelectObject = function () {
    this.SelectObject && this.SelectObject.hideSelect();
    this.SelectObject = null;
    this.OptionsView.cancelViewerForm();
};
viewStatus.prototype.setSelectObject = function (data) {
    this.SelectObject && this.SelectObject.hideSelect();
    this.SelectObject = data;
    var formOptions = data.viewObjectForm();
    this.OptionsView.renderViewerForm(formOptions);
    data.showSelect();
};

viewStatus.prototype.getSelectObject = function () {
    for (const key in this.status) {
        if (this.status.hasOwnProperty.call(this.status, key)) {
            const element = this.status[key];
            if (element.obj.isSelect) {
                return element.obj.isSelect
            };
        }
    };
    return null;
};

viewStatus.prototype.getObject = function (id) {
    return this.status[id];
};

viewStatus.prototype.addObject = function (obj, parent, e) {
    var data = {
        id: obj.basic.id,
        name: obj.basic.name,
        children: [],
        obj: obj,
        parent: parent || null,
    };
    this.status[data.id] = data;
    if (!parent) {
        this.statusKeyArray[data.id] = data;
    } else {
        parent.children.push(data.id);
    };
    this.BoardView.append(obj.$el);
    obj.setPosition(e.clientX, e.clientY, true);
    this.setSelectObject(obj);
};

viewStatus.prototype.changeIndex = function (id, form, to) {
    // 移动图层顺序
};


export default viewStatus;



